--
module("UI.Windows.AddZFBWin", package.seeall)

local UIUtility = require("UI.Utility")
local UIWindow = require("UI.UIWindow").UIWindow
local UIWinMgr = require("UI.UIWinMgr").UIWinMgr
local json = require("cjson")
AddZFBWin = UIWindow:new()

AddZFBWin.name = "AddZFBWin"


function AddZFBWin:Init()
	
	local t = self.Container.transform
 
    self.close_btn=UIUtility.GetChildTransform("close_btn", t, true)
	self:BindEvents()


    self.queren_btn = UIUtility.GetChildTransform("queren_btn", t, true)
    self.bank_user_name_input = UIUtility.FindContorl("UIInput", "bank_user_name_input", t)
    self.bank_cardNumber_input = UIUtility.FindContorl("UIInput", "bank_cardNumber_input", t)
    self.bank_passWord_input = UIUtility.FindContorl("UIInput", "bank_passWord_input", t)

    self.isAddCard = true
    self.curBankId = 0
    self.Data = {}
    --获取已存储的信息
    require("NetWork.NetHttp").SendGetRequest("/byr/payment/withdraw/info", function(ok, data)
        if ok then
            print("获取用户提现信息" .. stringify(data))
            for i = 1, #data.data do
                if data.data[i].withdrawMethod == 2 then
                    self.isAddCard = false
                    self.curBankId = data.data[i].withdrawId
                    self.Data = data.data[i]
                    self.bank_user_name_input.value = self.Data.accountName
                    self.bank_cardNumber_input.value = self.Data.aliPayAccount

                    break
                end
            end
        else
            print(stringify(data))
        end
    end)

    UIHelper.BindUIEvnet("Click", function()
        local saveBankJson 
        -- saveBankJson = string.format('{"withdrawId":%s,"withdrawMethod": 1,"accountName":"%s","bankName": "%s","cardNumber": "%s","secondPassword": "%s"}',
        --self.bank_user_name_input.value, self.xzyh_btn_lable.text, self.bank_cardNumber_input.value, self.bank_passWord_input.value)
        if self.isAddCard then
            saveBankJson = string.format(
                '{"withdrawMethod": 2,"accountName":"%s","aliPayAccount": "%s","secondPassword": "%s"}',
                self.bank_user_name_input.value, self.bank_cardNumber_input.value,self.bank_passWord_input.value)
        else
            saveBankJson = string.format(
                '{"withdrawId":%s,"withdrawMethod": 2,"accountName":"%s","aliPayAccount": "%s","secondPassword": "%s"}',
                self.curBankId, self.bank_user_name_input.value, self.bank_cardNumber_input.value,self.bank_passWord_input.value)
        end
        require("NetWork.NetHttp").SendPostRequest_token("/byr/payment/withdraw/saveOrUpdate", function(ok, data)
            if ok then
                print("添加银行卡" .. stringify(data))
                UIWinMgr:OpenTextNotice("支付宝设置成功")
                local NewGameLoobyWin = require("UI.Windows.NewGameLoobyWin").NewGameLoobyWin
                NewGameLoobyWin.user_data_zfbinfo = self.Data
                NewGameLoobyWin.secondPassword = self.bank_passWord_input.value
                self:Close(1)
                
            else
                UIWinMgr:OpenTextNotice(data.msg)
            end
        end, saveBankJson)
    end, self.queren_btn.gameObject)
end

function AddZFBWin:OnShow()
	
end

function AddZFBWin:OnClose()

end


function AddZFBWin:BindEvents()
    UIHelper.BindUIEvnet("Click", function()
    self:Close(1)
end, self.close_btn.gameObject)

end

